
var publicVehicleClassTypeConfig = {
    searchUrl: dictionary_service_url + '/FindDatailByType/VehicleType',
    vehicleclassTypePZ: [//需要查询的车辆类型配置种类
        {"CODE": "K33","NAME":"小型轿车"},
        {"CODE": "K30","NAME":"小型客车"},//客车
        {"CODE": "K20","NAME":"中型客车"},//
        {"CODE": "K10","NAME":"大型客车"},//大型普通客车
        {"CODE": "K32","NAME":"小型越野客车"},
        {"CODE": "K34","NAME":"小型专用客车"},
        {"CODE": "H40","NAME":"微型货车"},//货车
        {"CODE": "H20","NAME":"中型货车"},//中型普通货车
        {"CODE": "H10","NAME":"重型货车"},//大货车
        // {"CODE": "H93","NAME":"其他"},
        {"CODE": "99","NAME":"其他"},
        // {"CODE": "K98","NAME":"其他-1"}
    ],
    checkClass:'layui-form-checked',//.chooseall-style
    functions: {
        init: function () {
            this.initClass();
        },
        /**
         * 初始化分类函数
         */
        initClass: function () {
            var html="";
            $.each(publicVehicleClassTypeConfig.vehicleclassTypePZ,function (i,d) {
                html = ''
                    + '<div class="layui-unselect layui-form-checkbox eachspan" lay-skin="primary" spanflag="false"  data-code="'+d.CODE+'" onclick="publicVehicleClassTypeConfig.functions.singeCheck(this)">'
                    + '<span>'+d.NAME+'</span>'
                    + '<i class="layui-icon">&#xe605;</i>'
                    + '</div>';
                $("#vehicleclasscheck").append(html);
            });
            /*$.ajax({
             url: publicVehicleClassTypeConfig.searchUrl,
             type: "get",
             data: {
             type: "VehicleType"
             },
             success: function (data) {
             if (!data) {//add by YaoWei 解决数据为空时浏览器控制台报错
             return;
             }
             }
             });*/
			
        },
        /*全选-车辆类型*/
        chooseAllVehicleCClass: function (allObj) {
            var allflag = $(allObj).attr("spanflag");
            if (allflag == "true") {
                $(allObj).attr('spanflag', false);
                $('#vehicleclasscheck .eachspan').each(function (i, item) {
                    $(this).attr('spanflag', false);
                    $(this).removeClass(publicVehicleClassTypeConfig.checkClass);
                });
                $("#chooseall").removeClass(publicVehicleClassTypeConfig.checkClass);
            } else {
                $(allObj).attr('spanflag', true);
                $('#vehicleclasscheck .eachspan').each(function (i, item) {
                    $(this).attr('spanflag', true);
                    $(this).addClass(publicVehicleClassTypeConfig.checkClass);
                });
                $("#chooseall").addClass(publicVehicleClassTypeConfig.checkClass);
            }
        },
        singeCheck: function (picObj) {
            var flag = $(picObj).attr("spanflag");
            if (flag == "true") {
                $(picObj).attr("spanflag", false);
                $(picObj).removeClass(publicVehicleClassTypeConfig.checkClass);
                $("#chooseall").attr("spanflag", false);
                $("#chooseall").removeClass(publicVehicleClassTypeConfig.checkClass);
            } else {
                var allchooseflag = true;
                $(picObj).attr("spanflag", true);
                $(picObj).addClass(publicVehicleClassTypeConfig.checkClass);
                $('#vehicleclasscheck .eachspan').each(function (m, n) {
                    if ($(this).attr("spanflag") == "false") {
                        allchooseflag = false;
                    }
                });
                if (allchooseflag) {
                    $('#vehicleclasscheck .eachspan').attr("spanflag", true);
                    $("#chooseall").addClass(publicVehicleClassTypeConfig.checkClass);
                    $("#chooseall").attr("spanflag", true);
                }
            }
        },
        getValue:function () {
            var value=[];
            var qx = "+";
            $('#vehicleclasscheck .eachspan').each(function (m, n) {
                if ($(this).attr("spanflag") == "true") {
                    value.push($(this).attr("data-code"));
                }
            });
            if ($("#chooseall").attr("spanflag") == "true") {
                qx = "-";
                return qx;
            } else {
                return value.toString();
            }
        }
    }
};
$(function(){
    publicVehicleClassTypeConfig.functions.init();
});